import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
//	--6，TODO 练习反射
//	--准备类(public/private/default)
//	--获取类里构造方法(getConstructor)并new对象(newInstance)
//	--获取类里普通方法(getMethod)并执行方法(invoke)
//	--获取类里成员变量(getField)并set()/get()

public class fanshe {
    public static void main(String[] args) throws Exception {
        //one1();
        //one2();
       //one3();
       method1();
    }

    private static void method1() throws Exception {
        Class c3 = one.class;
        Constructor[] a = c3.getConstructors();
        for (Constructor con : a) {
            //System.out.println(con.getName());
            Class[] a1 = con.getParameterTypes();
            if(a1.length==0){
               Object o = con.newInstance();
                System.out.println(o);
            }else if(a1.length!=0){
                Object o1 = con.newInstance("abc",123);
                System.out.println(o1);
            }
        }
    }

    private static void one3() throws Exception {
        Class c2 = one.class;
        Field[] cc2 = c2.getFields();
        for (Field a : cc2) {
            //System.out.println(a.getName());
            if (a.getName().equals("a")) {
                Object obj = c2.newInstance();
                a.set(obj,"12");
                System.out.println(a.get(obj));
            }
        }
    }

    private static void one2() throws Exception {
        Class c1 = one.class;
        Method m1 = c1.getMethod("one2",int.class);
        Object m2 = c1.newInstance();
        m1.invoke(m2,12);
    }

    public static void one1() throws Exception {
        Class cl = one.class;
       //Object c = cl.newInstance();
        Constructor b = cl.getConstructor(String.class,int.class);
        one b2 = (one) b.newInstance("abc",1);
        b2.one2(123);
        b2.one3("bbb");
    }


}

